# !/usr/bin/env python
# coding=utf-8
# @Time    : 2017/12/29 10:01
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/wx_server_prototype.git
# @File    : multi_threads_coroutines.py
# @Software: PyCharm
# @Version: 3.5.4
import os
import threading
import ctypes
import time
import requests
from utils.my_exception import MyException


def pthread_level1(i):
	print("workor id :%s" % i)
	# 获取threading对象的标识ident
	print(threading.currentThread())
	# print threading.currentThread().ident
	co = coroutine(i)
	co.__next__()
	co.__next__()
	co.__next__()
	co.__next__()
	# co.__next__()
	print('=================')
	# print "threaing id: ", ctypes.CDLL('libc.so.6').syscall(186)
	# d = requests.get("http://www.baidu.com")

	time.sleep(100)
	return


def coroutine(i):
	n = 0
	while n < 3:
		yield
		n = n + 1
		print('------', i, '-------', threading.currentThread(), '/n')
		time.sleep(1)


if __name__ == "__main__":
	l = []
	for i in range(5):
		t = threading.Thread(target=pthread_level1, args=(i,))
		l.append(t)
	for i in l:
		i.start()
	# 查看进程跟线程的关系
	# os.system("pstree -p " + str(os.getpid()))
	for i in l:
		i.join()

	print("Sub-process done.")